<style scoped>
  .weui-form-preview__hd label, .weui-form-preview__hd em {
    font-size: .9em !important;
  }
  .weui-loadmore_line .weui-loadmore__tips {
    background-color: #eee;
  }
  .rj-cell.max span{
    font-size: 16px;
    padding-right: 20px;
  }
  .rj-cell label {
    color: #333;
    font-size: 14px;
    width: 44%;
    display: inline-block;
    padding: 5px 3%;
    text-align: right;
  }
  .rj-cell span {
    font-size: 14px;
    color: #333;
    display: inline-block;
    width: 50%;
  }
  .rj-cell.note label{
    float: left;
  }
  .rj-cell.note span{
    width: 80%;
    display: inline-block;
  }
  .weui-cells {
    margin-top: 0;
  }
  .weui-cells_form {
    background: #fbfbfb;
  }
  .weui-cell {
    background: #fff;
  }
  .weui-cells__title {
    text-align: left;
  }
  .oitem {
    padding: 3px;
  }
  .hide {
    display: none;
  }
  #acts {
    font-size: 0;
  }
  #acts span {
    font-size: 14px;
  }
  .halfbtn {
    display: inline-block;
    width: 49%;
  }
  .weui-label {
    text-align: left;
  }

  .weui_uploader_input_wrp {
    float: left;
    position: relative;
    margin-right: 9px;
    margin-bottom: 9px;
    width: 77px;
    height: 77px;
    border: 1px solid #D9D9D9;
  }
  .weui_uploader_hd {
    padding-top: 0;
    padding-right: 0;
    padding-left: 0;
  }
  .weui_uploader_files {
    list-style: none;
  }
  .weui_uploader_input_wrp:before {
    width: 2px;
    height: 39.5px;
  }
  .weui_uploader_input_wrp:before, .weui_uploader_input_wrp:after {
    content: " ";
    position: absolute;
    top: 50%;
    left: 50%;
    -webkit-transform: translate(-50%, -50%);
    transform: translate(-50%, -50%);
    background-color: #D9D9D9;
  }
  .weui_uploader_input {
    position: absolute;
    z-index: 1;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
  }
  .weui_uploader_input_wrp:after {
    width: 39.5px;
    height: 2px;
  }
  .weui_uploader_bd {
    overflow: hidden;
  }
  .weui_cell {
    padding: 10px 15px;
    position: relative;
    display: -webkit-box;
    display: -webkit-flex;
    display: -ms-flexbox;
    display: flex;
    -webkit-box-align: center;
    -webkit-align-items: center;
    -ms-flex-align: center;
    align-items: center;
    background: #fff;
  }
  .examine >>> .weui-uploader_files {
    list-style: none;
    overflow-y: hidden;
  }
  .examine >>> .weui-uploader_file {
    float: left;
    margin-right: 9px;
    margin-bottom: 9px;
    width: 79px;
    background: no-repeat 50%;
    background-size: cover;
  }
  .weui-cell_select {
    padding: 0 15px;
  }
  .weui-select {
    height: auto;
    line-height: normal;
  }
</style>
<template>
  <div class="examine">
    <div class="rj-wrap">
      {{title}}
      <a href="javascript:;" @click="$router.back(-1)" style="position: absolute; left: 10px; top: 8px">
        <img src="@/assets/back.png" style="width: 20px" />
      </a>
    </div>
      <div class="weui-cells weui-cells_form">
      <form action="" method="post" id="formid">
        <input class="weui-input" type="hidden" name="entitySea.guid" :value="id" >
        <div class="weui-cells weui-cells_form">
            <div class="weui-cell">
              <div class="weui-cell__hd">
                <label class="weui-label">收货港口</label>
              </div>
              <div class="weui-cell__bd">
                <input type="hidden" name="entitySea.arriPort" :value="checkObjNull(arriPort).name" />
                <select class="weui-select" v-model="arriPort" style="width: 60%; display: inline-block;overflow: hidden;">
                  <option value="">请选择</option>
                  <option v-for="(item, index) in arriPorts" :value="item" :style="item.guid == 999 ? 'color: blue;' : ''">
                    {{item.name}}
                  </option>
                </select>
                <input class="weui-input" name="entitySea.arriPortCountry" type="text" v-model="arriPortCountry" placeholder="所属国家"  style="width: 35%; display: inline-block;overflow: hidden;">
            </div>
            </div>
<!--            <div class="weui-cell">-->
<!--              <div class="weui-cell__hd">-->
<!--                <label class="weui-label">收货港所属国家</label></div>-->
<!--              <div class="weui-cell__bd">-->
<!--                <input class="weui-input" name="entitySea.arriPortCountry" type="text" v-model="arriPortCountry" ></div>-->
<!--            </div>-->
          <div class="weui-cell">
            <input type="hidden" name="entitySea.environment" :value="seaTemp + ' ' + seaWind" />
            <div class="weui-cell__hd"><label class="weui-label">温度</label></div>
            <div class="weui-cell__bd">
              <select class="weui-select" v-model="seaTemp">
                <option value="">请选择</option>
                <option v-for="(item, index) in seaTemperatures" :key="item.dictkey" :value="item.dicttext">
                  {{item.dicttext}}
                </option>
              </select>
            </div>
          </div>
          <div class="weui-cell">
            <div class="weui-cell__hd"><label class="weui-label">通风情况</label></div>
            <div class="weui-cell__bd">
              <select class="weui-select" v-model="seaWind">
                <option value="">请选择</option>
                <option v-for="(item, index) in seaWinds" :key="item.dictkey" :value="item.dicttext">
                  {{item.dicttext}}
                </option>
              </select>
            </div>
          </div>
<!--            <div class="weui-cell">-->
<!--              <div class="weui-cell__hd">-->
<!--                <label class="weui-label">海运环境</label></div>-->
<!--              <div class="weui-cell__bd">-->
<!--                <input class="weui-input" name="entitySea.environment" type="text" :value="baseInfo.environment" ></div>-->
<!--            </div>-->
            <div class="weui-cell">
              <div class="weui-cell__hd">
                <label class="weui-label">提单类型</label>
              </div>
              <div class="weui-cell__bd">
                <select class="weui-select" name="entitySea.lifttype">
                  <option v-for="(item, index) in liftTypes" v-model="liftType" :key="item.dictkey" :value="item.dictkey">
                    {{item.dicttext}}
                  </option>
                </select>
              </div>
            </div>
            <div class="weui-cell">
              <div class="weui-cell__hd">
                <label class="weui-label">贸易条款</label></div>
              <div class="weui-cell__bd">
                <select class="weui-select" name="entitySea.transClause" v-model="transClause">
                  <option value="">请选择</option>
                  <option v-for="(item, index) in transClauses" :key="item.dictkey" :value="item.dicttext">
                    {{item.dicttext}}
                  </option>
                </select>
              </div>
            </div>
            <div class="weui-cell">
              <div class="weui-cell__hd">
                <label class="weui-label">备注</label></div>
              <div class="weui-cell__bd">
                <input class="weui-input" name="entitySea.remark" type="text" v-model="baseInfo.remark"></div>
            </div>
            <div class="weui-cell">
              <div class="weui-cell__hd">
<!--                <div class="delsty"><i class="weui-icon-cancel" v-on:click="deleteSeaCar"></i></div>-->
                <label class="weui-label">物流公司</label></div>
              <div class="weui-cell__bd">
                <input class="weui-select" type="hidden" name="entitySea.customerid" :value="currCustomer != null ? currCustomer.guid : ''">
                <input class="weui-select" type="hidden" name="entitySea.customername" :value="currCustomer != null ? currCustomer.name : ''">
                <select class="weui-select" v-model="currCustomer">
                  <option value="">请选择物流公司</option>
                  <option v-for="(item, index) in wlcompanys" :value="item">
                    {{item.name}}
                  </option>
                </select>
              </div>
<!--                <input class="weui-select" type="hidden" name="entitySea.customeridSea" :value="currCustomer.customerid" id="customeridSea">-->
<!--                <input class="weui-select" type="text" name="entitySea.customernameSea" v-model="currCustomer" id="customernameSea" placeholder="请选择物流公司" style="width: 80%;"></div>-->
            </div>
<!--            <div class="weui-cell">-->
<!--              <div class="weui-cell__hd">-->
<!--                <label class="weui-label">货柜号</label></div>-->
<!--              <div class="weui-cell__bd">-->
<!--                <input class="weui-input" type="text" id="containerNo" name="entitySea.containerNo" v-model="baseInfo.containerNo" placeholder="请输入货柜号"></div>-->
<!--            </div>-->
            <div class="weui-cell">
              <div class="weui-cell__hd">
                <label class="weui-label">发货港口</label></div>
              <div class="weui-cell__bd">
                <input type="hidden" name="entitySea.deliPort" :value="checkObjNull(deliPort).name" />
                <select class="weui-select" id="deliPort" v-model="deliPort">
                  <option value="">请选择</option>
                  <option v-for="(item, index) in deliPorts" :value="item" :style="item.guid == 999 ? 'color: blue;' : ''">
                    {{item.name}}
                  </option>
                </select>
<!--                <input class="weui-input" type="text" id="deliPort" name="entitySea.deliPort" v-model="baseInfo.deliPort" placeholder="请输入发货港口"></div>-->
              </div>
            </div>

            <div class="weui-cell">
              <div class="weui-cell__hd">
                <label class="weui-label">货运船公司</label></div>
              <div class="weui-cell__bd">
                <input class="weui-input" type="text" name="entitySea.shipCompany" v-model="baseInfo.shipCompany"  placeholder="货运船所属公司"></div>
            </div>
            <div class="weui-cell">
              <div class="weui-cell__hd">
                <label class="weui-label">船名称</label></div>
              <div class="weui-cell__bd">
                <input class="weui-input" type="text" name="entitySea.shipname" v-model="baseInfo.shipname"  placeholder="请输入船名称"></div>
            </div>
            <div class="weui-cell">
              <div class="weui-cell__hd">
                <label class="weui-label">航次</label></div>
              <div class="weui-cell__bd">
                <input class="weui-input" type="text" name="entitySea.shipCode" v-model="baseInfo.shipCode"  placeholder="请输入航次"></div>
            </div>
            <div class="weui-cell">
              <div class="weui-cell__hd">
                <label class="weui-label">提单号</label></div>
              <div class="weui-cell__bd">
                <input class="weui-input" ref="liftCode" type="text" name="entitySea.liftCode" v-model="baseInfo.liftCode"  placeholder="请输入提单号"></div>
            </div>
            <div class="weui-cell">
              <div class="weui-cell__hd">
                <label class="weui-label">箱型</label></div>
              <div class="weui-cell__bd">
                <select class="weui-select" name="entitySea.boxType" ref="boxType">
                  <option value="">请选择</option>
                  <option v-for="item in boxTypes" :value="item.name" :selected="baseInfo.boxType == item.name">{{item.name}}</option>
                </select>
              </div>
              <!--                  <input class="weui-input" ref="boxType" type="text" name="entitySea.boxType" v-model="baseInfo.boxType"  placeholder="请输入箱型"></div>-->
            </div>
            <div class="weui-cell">
              <div class="weui-cell__hd">
                <label class="weui-label">箱数</label></div>
              <div class="weui-cell__bd">
                <input class="weui-input" ref="boxSize" type="number" name="entitySea.boxSize" v-model="baseInfo.boxSize"  placeholder="请输入箱数"></div>
            </div>
            <div class="weui-cell">
              <div class="weui-cell__hd">
                <label class="weui-label">开船日期</label>
              </div>
              <div class="weui-cell__bd">
                <input type="text" id='datetime-picker' ref="loadtime" class="weui-input time" name="loadtime" v-model="loadtime" placeholder="请选择开船日期" />
              </div>
            </div>
<!--            <div class="weui-cell">-->
<!--              <div class="weui-cell__hd">-->
<!--                <label class="weui-label">集装箱号</label></div>-->
<!--              <div class="weui-cell__bd">-->
<!--                <input class="weui-input" ref="boxCode" type="text" name="entitySea.boxCode" v-model="baseInfo.boxCode"  placeholder="请输入集装箱号"></div>-->
<!--            </div>-->
          <div class="weui-btn-area">
            <a class="weui-btn weui-btn_primary halfbtn subbtn" href="javascript:" @click="postForm">提交</a>
            <a class="weui-btn weui-btn_primary halfbtn"  href="javascript:" @click="$router.back(-1)" id="sub">返回</a>
          </div>

        </div>
      </form>
    </div>
    <div id="bmlogs">
      <OperationLogs2 :nodeid="nodeid" :orderid="id" :srguid="''" :departid="baseInfo.departid"></OperationLogs2>
    </div>

  </div>
</template>

<script>
  import wx from 'weixin-js-sdk';
  import OperationLogs2 from '../common/OperationLogs2'

export default {
  name: 'Book',
  data () {
    return {
      id: '',
      title: '',
      baseInfo: '',
      wxParams: {},
      nodeid: '',
      annex: '',
      images: {
        serverId: [],
        srcStr: [],
      },
      arriPorts: '',
      arriPort: '',
      deliPorts: '',
      deliPort: '',
      liftTypes: '',
      liftType: '',
      transClauses: '',
      transClause: '',
      boxTypes: '',
      arriPortCountry: '',
      seaWinds: '',
      seaWind: '',
      seaTemp: '',
      seaTemperatures: '',
      wlcompanys: [],
      currCustomer: '',
      loadtime: ''
    }
  },
  components: {
    OperationLogs2
  },
  watch: {
    arriPort: function (val) {
      if (val != undefined) {
        this.arriPortCountry = val.country;
        if (val.guid == 999) {
          this.addPort('arri');
        }
      }
    },
    deliPort: function (val) {
      if (val != undefined && val.guid == 999) {
        this.addPort('deli');
      }
    }
  },
  mounted () {
    let that = this;
    //提交操作定位到页面底部
    //$('#bmlogs').css('margin-bottom', this.$refs.actHtml.offsetHeight)

    //日历初始化
    $("#datetime-picker").calendar({
      dateFormat: 'yyyy-mm-dd'
    });

    this.id = this.$route.query.guid;
    this.title = this.$route.query.title;
    this.nodeid = this.$route.query.nodeid;
    this.annex = this.$route.query.annex;
    this.getBaseInfo(this.id, this);
    this.getArriPorts();
    this.getSeaTemps();
    this.getSeaWinds();
    this.getLifttypes();
    this.getTransClauses();
    this.getboxTypes();
    this.getWlcompanys();
    //获取回显数据
    $.ajax({
      url: '/sales/Sellform!getWlCompany.action',
      data: {},
      type: "post",
      dataType: "json",
      success: function(res) {
        if (res.info != null) {

          var data = res.info;
          var datalist = new Array;
          $.each( data, function( index, itsm ) {
            var info = { "title": itsm.name, "value": itsm.guid };
            datalist.push(info);
          });

          $('#customername').select({
            title: "物流公司",
            items: datalist,
            onChange: function (data) {
              $('input[name="faretype"]').val($('#wlcompany').data('values'));
              $('#customername').val(data.titles);
              $('#customerid').val(data.values);
            }
          });

          // $('#customernameSea').select({
          //   title: "物流公司",
          //   items: datalist,
          //   onChange: function (data) {
          //     $('#customernameSea').val(data.titles);
          //     $('#customeridSea').val(data.values);
          //   }
          // });
        } else if (res != undefined && res.msg == 'sessionTimeOut') {
          //不不设置提示
        } else {
          that.toastError('系统出现异常!');
        }
      },
      complete: function () {

      }
    });
  },
  computed: {

  },
  methods: {
    wxConfig: function(wxParams) {
      wx.config({
        debug: false,            // 开启调试模式,调用的所有api的返回值会在客户端this.toastText出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。
        appId: wxParams.appid,    // 必填，公众号的唯一标识
        timestamp: wxParams.timestamp,  // 必填，生成签名的时间戳
        nonceStr: wxParams.nonceStr, // 必填，生成签名的随机串
        signature: wxParams.signature,// 必填，签名
        jsApiList: ['scanQRCode', 'chooseImage', 'uploadImage'] // 必填，需要使用的JS接口列表
      });
    },
    wxUoloadImage: function(that) {
      let cthis = this;
      //wx.ready(function(){
      // config信息验证后会执行ready方法，所有接口调用都必须在config接口获得结果之后，config是一个客户端的异步操作，所以如果需要在页面加载时就调用相关接口，则须把相关接口放在ready函数中调用来确保正确执行。对于用户触发时才调用的接口，则可以直接调用，不需要放在ready函数中。
      document.querySelector('#selectImage').onclick = function () {
        wx.chooseImage({
          success: function (res) {
            $(function(){
              $.each( res.localIds, function(i, n){
                wx.uploadImage({
                  localId: n,
                  isShowProgressTips: 1,
                  success: function (res) {
                    if (that.checkCore() == 'ios') {
                      wx.getLocalImgData({
                        localId: n, // 图片的localID
                        success: function (res2) {
                          cthis.$nextTick(function () {
                            cthis.images.srcStr.push(res2.localData);
                          })
                        }
                      });
                    } else {
                      cthis.$nextTick(function () {
                        cthis.images.srcStr.push(n);
                      })
                    }

                    cthis.images.serverId.push(res.serverId);
                  },
                  fail: function (res) {
                    this.toastText(JSON.stringify(res));
                  }
                });
              });
            });
          }
        });
      };
      //});

    },
    del: function (id){
      let cthis = this;
      $.actions({
        actions: [{
          text: "删除",
          onClick: function() {
            $.confirm("确定删除?", function() {
              //点击确认后的回调函数
              //删掉id
              var ids = cthis.images.serverId;
              var a =  ids.indexOf(id);
              cthis.$nextTick(function () {
                cthis.images.serverId.splice(a,1);
                cthis.images.srcStr.splice(a,1);
              })
              //$("#"+id).hide();
            }, function() {
              //点击取消后的回调函数
            });
          }
        }
        ]
      });
    },
    checkCore:function() {
      var u = navigator.userAgent;
      //var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Linux') > -1;//g
      var isIOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/);   //ios终端
      if (isIOS) {
        return 'ios';
      } else  {
        return 'android';
      }
    },
    getBaseInfo: function(id, that) {
      this.axios({
        method: 'post',
        url: '/wlinfo/Wlinfo!getUpImagInfo.action',
        params: {wlinfoid: id, url: location.href.split("#")[0]}
      }).then(response => {
        if (response.data.msg == 'success') {
          this.baseInfo = response.data.wlinfo;

          if (this.arriPorts != '' && this.arriPort == '') {
            this.arriPort = this.arriPorts.filter(item => {
              return item.name == this.baseInfo.arriPort;
            })[0];
          }
          if (this.deliPorts != '' && this.deliPort == '') {
            this.deliPort = this.deliPorts.filter(item => {
              return item.name == this.baseInfo.deliPort;
            })[0];
          }
          this.loadtime = this.baseInfo.loadtime;
          this.liftType = this.baseInfo.liftType;
          this.transClause = this.baseInfo.transClause;
          this.arriPortCountry = this.baseInfo.arriPortCountry;
          let environment = this.baseInfo.environment.split(' ');
          this.seaTemp = environment[0] + ' ' + environment[1];
          this.seaWind = environment[2] + ' ' + environment[3];
          if (this.wlcompanys.length > 0) {
            this.currCustomer = this.wlcompanys.filter(item => {
              return item.guid == this.baseInfo.customerid;
            })[0];
          }

          let wxParams = response.data.params;
          //配置微信公众号参数
          this.wxConfig(response.data.params);
          //上传
          // this.wxUoloadImage(that);
        } else if (response != undefined && response.data != undefined && response.data.msg == 'sessionTimeOut') {
          //不不设置提示
        } else {
          this.toastError('系统错误');
        }
      });
    },
    addPort: function(type) {
      let that = this;
      let addHtml = '<div class="cellgroup"> <div class="weui-cell"> <div class="weui-cell__hd"><label class="weui-label" style="width: 70px;text-align: left;">港口名称</label></div> <div class="weui-cell__bd"> <input class="weui-input" type="text" name="name" placeholder="请输入名称"> </div> </div> <div class="weui-cell"> <div class="weui-cell__hd"><label class="weui-label" style="width: 70px;text-align: left;">所属国家</label></div> <div class="weui-cell__bd"> <input class="weui-input" type="text" name="country" placeholder="请输入国家"> </div> </div> </div>';
      $.modal({
        title: '添加港口',
        text: addHtml,
        buttons: [
          { text: "确定", onClick: function(){
              if ($('input[name="name"]').val() == '') {
                that.toastText('请输入港口名称');
                return;
              }
              if ($('input[name="country"]').val() == '') {
                that.toastText('请输入所属国家');
                return;
              }
              let name = $('input[name="name"]').val();
              let country = $('input[name="country"]').val();
              that.axios({
                method: 'post',
                url: '/sales/Port!addOrupdate.action',
                params: {name: name, country: country, type: type == 'arri' ? 2 : 1}
              }).then(response => {
                if (response.data.msg == "success") {
                  that.getArriPorts(type, name);
                } else if (response.data.isrepeat == "true") {
                  that.toastText('该港口已存在');
                } else {
                  this.toastText('添加港口失败');
                }
              });
            }},
          { text: "取消", className: "default", onClick: function(){
              if (type == 'arri') {
                that.arriPort = '';
              } else {
                that.deliPort = '';
              }
            }},
        ]
      });
    },
    getSeaTemps: function () {
      let that = this;
      this.axios({
        method: 'get',
        responseType: 'json',
        url: '/sales/Sellform!findDict.action',
        params: {type: 120}
      }).then(response => {
        if (response.statusText == "OK") {
          that.seaTemperatures = response.data;
        } else {
          this.toastText('获取海运温度数据失败');
        }
      });
    },
    getSeaWinds: function () {
      let that = this;
      this.axios({
        method: 'get',
        responseType: 'json',
        url: '/sales/Sellform!findDict.action',
        params: {type: 121}
      }).then(response => {
        if (response.statusText == "OK") {
          that.seaWinds = response.data;
        } else {
          this.toastText('获取海运通风数据失败');
        }
      });
    },
    getArriPorts: function (type = '', name = '') {
      let that = this;
      this.axios({
        method: 'get',
        responseType: 'json',
        url: '/sales/Port!listNopage.action',
        // params: {type}
      }).then(response => {
        if (response.data.msg == "success") {
          if (name != '') {
            if (type == 'arri') {
              that.arriPorts = response.data.ports.filter(item => {
                return item.type == 2;
              }).concat({guid: 999, name: '添加港口', country: ''});
              that.arriPort = that.arriPorts.filter(item => {
                return item.name == name;
              })[0];
            } else {
              that.deliPorts = response.data.ports.filter(item => {
                return item.type == 1;
              }).concat({guid: 999, name: '添加港口', country: ''});
              that.deliPort = that.deliPorts.filter(item => {
                return item.name == name;
              })[0];
            }
          } else {
            that.arriPorts = response.data.ports.filter(item => {
              return item.type == 2;
            }).concat({guid: 999, name: '添加港口', country: ''});
            that.deliPorts = response.data.ports.filter(item => {
              return item.type == 1;
            }).concat({guid: 999, name: '添加港口', country: ''});
            if (this.baseInfo != '' && this.arriPort == '') {
              that.arriPort = that.arriPorts.filter(item => {
                return item.name == this.baseInfo.arriPort;
              })[0];
            }
            if (this.baseInfo != '' && this.deliPort == '') {
              that.deliPort = that.deliPorts.filter(item => {
                return item.name == this.baseInfo.deliPort;
              })[0];
            }
          }
        } else {
          this.toastText('获取海运港口数据失败');
        }
      });
    },
    //获取海运提单类型（正本、电放）
    getLifttypes: function () {
      let that = this;
      this.axios({
        method: 'get',
        responseType: 'json',
        url: '/sales/Sellform!findDict.action',
        params: {type: 118}
      }).then(response => {
        if (response.statusText == "OK") {
          that.liftTypes = response.data;
        } else {
          this.toastText('获取海运提单类型数据失败');
        }
      });
    },
    //获取海运贸易条款
    getTransClauses: function () {
      let that = this;
      this.axios({
        method: 'get',
        responseType: 'json',
        url: '/sales/Sellform!findDict.action',
        params: {type: 117}
      }).then(response => {
        if (response.statusText == "OK") {
          that.transClauses = response.data;
        } else {
          this.toastText('获取海运贸易条款数据失败');
        }
      });
    },
    getboxTypes: function() {
      this.axios({
        url: '/sales/Boxtype!getBox.action'
      }).then(response => {
        if (response.data.msg == "success") {
          this.boxTypes = response.data.boxs;
        } else {
          this.toastText(获取箱型数据失败);
        }
      })
    },
    getWlcompanys: function() {
      this.axios({
        url: '/sales/Sellform!getWlCompany.action'
      }).then(response => {
        if (response.data.info != null) {
          this.wlcompanys = response.data.info;
          if (this.baseInfo != '') {
            this.currCustomer = this.wlcompanys.filter(item => {
              return item.guid == this.baseInfo.customerid;
            })[0];
          }
        } else {
          this.toastText(获取物流公司数据失败);
        }
      })
    },
    deleteSeaCar: function(){
      let that = this;
      var result = confirm("确认删除该派船信息？");
      if(!result){
        return;
      }
      var guid = $("#guid").val();
      if($('#customeridSea').val() == null || $('#customeridSea').val() == ""){
        that.toastText("该物流还没有进行派船");
        return;
      }
      $.ajax({
        url: '/wlinfo/Wlinfo!deleteSeaCar.action',
        data: {linkcode : this.order.sellcode},
        type: "get",
        dataType: "json",
        success: function(res) {
          console.log("res",res)
          if(res.msg == "删除成功"){
            $('#containerNo').val("");
            $("#deliPort").val("")
            $("#arriPort").val("")
            $("#customeridSea").val("")
            $("#customernameSea").val("")
            that.toastText(res.msg)
            if (that.wlinfoitem.wlstatus == 2) {
              that.$router.push({name: 'Sellform'});
            }
          }else{
            that.toastText(res.msg)
            // return;
          }
        }
      });
    },
    postForm: function () {
      let that = this;
      if (this.currCustomer == '' || this.currCustomer == undefined) {
        this.toastText('请选择物流公司');
        return false;
      } else if (this.seaTemp == '') {
        this.toastText('请输入海运温度条件！');
        return false;
      } else if (this.seaWind == '') {
        this.toastText('请输入海运通风情况！');
        return false;
      } else if (this.arriPort == '' || this.arriPort == undefined) {
        this.toastText('请选择收货港口！');
        return false;
      } else if (this.deliPort == '' || this.deliPort == undefined) {
        this.toastText('请选择收货港口！');
        return false;
      } else if (this.arriPortCountry == '' || this.arriPortCountry == undefined){
        this.toastText('请输入收货港口所属国家！');
        return false;
      }

      // if($("#containerNo").val() == 0){
      //   this.toastText("请输入货柜号");
      //   return false;
      // }
      if($("#deliPort").val() == 0){
        this.toastText("请输入发货港口");
        return false;
      }
      if(that.$refs.liftCode.value == ''){
        this.toastText("请输入海运提单号");
        return false;
      }
      if(that.$refs.boxType.value == ''){
        this.toastText("请选择海运箱型");
        return false;
      }
      if(that.$refs.boxSize.value == ''){
        this.toastText("请输入海运箱数");
        return false;
      }
      if (that.$refs.loadtime.value == '' || that.$refs.loadtime.value == undefined) {
        this.toastText('开船日期不能为空！');
        return false;
      }
      // if(that.$refs.boxCode.value == ''){
      //   this.toastText("请输入海运集装箱号");
      //   return false;
      // }
      //防止重复提交
      $('.subbtn').attr("disabled",true).css("pointer-events","none");
        //显示提交状态
        $.showLoading("正在提交");

      let postData = this.serialize2Obj($("#formid").serializeArray());
      postData.nodeid = this.nodeid;
      // postData.opinion = $('#opinion').val() != '' ? $('#opinion').val() : '同意';
      this.axios({
        method: 'post',
        url: '/wlinfo/Wlinfo!sendSea.action',
        params: postData
      }).then(response => {
        //恢复提交按钮可点击
        $('.subbtn').attr('disabled', false).css("pointer-events","auto");
          //关闭提交状态
          $.hideLoading();

        if (response.data.msg == 'success') {
          this.toastSuccess('提交成功!');
          this.$router.push({name: 'BookShip'});
        } else if (response.data.msg == 'canotopt') {
          this.toastText('不允许的操作！');
        } else if (response != undefined && response.data != undefined && response.data.msg == 'sessionTimeOut') {
          //不不设置提示
        } else {
          this.toastError('系统错误');
        }
      }).catch(function (error) {
        //恢复提交按钮可点击
        $('.subbtn').attr('disabled', false).css("pointer-events","auto");
          //关闭提交状态
          $.hideLoading();
        that.toastError('系统错误');
      });
    },
    openLogs: function() {
      this.$router.push({name: 'OperationLogs2', query: {orderid: this.id, srguid: '', departid: this.baseInfo.departid}});
    }
}
}
</script>
